package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Order;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/4/28
 * @description
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Value("${server.port}")
    private String port;

    //  openfeign 进行请求发送时 默认如果在1s之内没有得到响应 则直接抛出异常
    //  后期可设置请求超时时间
    @RequestMapping("m1")
    public String method1() {

        // try {
        //     Thread.sleep(3000);
        // } catch (InterruptedException e) {
        //     throw new RuntimeException(e);
        // }
        return "orderService ok port = "+port;
    }

    @RequestMapping("m2")
    public String method2(Integer uid) {
        return "orderService ok port = "+port+" uid = "+uid;
    }

    @RequestMapping("m3/{uid}")
    public String method3(@PathVariable Integer uid) {
        return "orderService ok port = "+port+" uid = "+uid;
    }

    @RequestMapping("m4")
    public String method4(Order order) {
        return "orderService ok port = "+port+" ; "+order;
    }

    @RequestMapping("m5")
    public String method5(@RequestBody Order order) {
        return "orderService ok port = "+port+" ; "+order;
    }


    @RequestMapping("m6")
    public String method6(Integer[] ids) {

        return "orderService ok port = "+port+" ; "+ Arrays.toString(ids);
    }

    @RequestMapping("m7")
    public List<Order>  method7(Integer uid) {
        Order order = new Order();
        order.setId(uid);
        order.setProductName("xiaomi");
        List<Order> list = Arrays.asList(order, order, order);

        return list;
    }

    @RequestMapping("m8")
    public Order  method8(Integer id) {
        Order order = new Order();
        order.setId(id);
        order.setProductName("xiaomi");
        return order;
    }

}
